#define  _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    vector<vector<int>> floodFill(vector<vector<int>>& image, int sr, int sc, int color) {
        int dx[4] = { 0,0,1,-1 };
        int dy[4] = { 1,-1,0,0 };
        int m = image.size(), n = image[0].size();
        vector<vector<int>> ret(image.begin(), image.end());
        int org = image[sr][sc];
        if (org == color) return ret;
        function<void(int, int)> dfs = [&](int r, int c)
            {
                ret[r][c] = color;
                for (int i = 0; i < 4; i++)
                {
                    int x = r + dx[i];
                    int y = c + dy[i];
                    if (x >= 0 && y >= 0 && x < m && y < n && ret[x][y] == org)
                        dfs(x, y);
                }
            };
        dfs(sr, sc);
        return ret;
    }
};